﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SpeakerRecognition
{
    /// <summary>
    /// Class for computing the Fast Fourier Transform of the double array
    /// </summary>
    public class FFTCommand : ICommand
    {
        //************************  Private Fields  *******************************// 
        private double[] inputData;
        private Complex[] outputComplexData;
        private double[] magnitudeData;
        private bool realOnly = true;

        
        //************************  Constructors    *******************************// 
        public FFTCommand()
        {

        }

        public FFTCommand(bool RealOnly)
        {
            realOnly = RealOnly;
        }
        //************************  Public Properties  ****************************//
        public Complex[] OutputComplexData
        {
            get { return outputComplexData; }
            set { outputComplexData = value; }
        }

        public bool RealOnly
        {
            get { return realOnly; }
            set { realOnly = value; }
        }

        public double[] MagnitudeData
        {
            get { return magnitudeData; }
            set { magnitudeData = value; }
        }

        public double[] InputData
        {
            get { return inputData; }
            set { inputData = value; }
        }
        //************************  Public Methods  ****************************// 
        #region ICommand Members

        public void execute()
        {       // use fft on the double array and get the complex result in the frequency domain
            outputComplexData = FFT.fft(FFT.convertToComplex(inputData));
                // get the magnitudes of the complex results according to the flag of Real or Image 

            magnitudeData = FFT.getMagnitude(outputComplexData, RealOnly);
        }

        #endregion

    }
}
